#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
#include <string.h>
int main()
{
    int n = 0, k = 0, i = 0, j = 0;
    char c[20] = { 0 };
    scanf("%d %d", &n, &k);
    for (i = 0; i < n; i++)
    {
        scanf("%s",c);
    }
    for (i = 0; i < n; i++)
    {
        for (k = k - 1; k >= 0; k--)
        {
            if (strcmp(c[i], c[i + 1]) > 0)
            {
                char t = c[i];
                c[i] = c[i + 1];
                c[i + 1] = t;

            }
        }
    }
    for (i = 0; i < n; i++)
    {
        puts(c);
    }


    return 0;
}